//发送短信验证码
var send_code = document.querySelector('.send_code');
var times = 59;
send_code.addEventListener('click',function(){
    this.disabled = true;
    var timer = setInterval(function(){
        if(times == 0){
            clearInterval(timer);
            send_code.disabled = false;
            send_code.value = '获取验证码';
            times = 59;
        }
        else{
            send_code.value = '还剩下' + times + '秒';
        times--;
        }
    },1000);
})

// 验证手机号格式是否正确
var reg1 = /^(13[0-9]|14[5|7]|15[0|1|2|3|4|5|6|7|8|9]|18[0|1|2|3|5|6|7|8|9])\d{8}$/;
$(".tel").blur(function(){
    if(reg1.test($(this).val())){
        $(this).siblings("span").attr("class","success");
        $(this).siblings("span").html("<i class='success_ico'></i>手机号输入正确")
    }else{
        $(this).siblings("span").attr("class","error");
        $(this).siblings("span").html("<i class='error_ico'></i>手机号码格式不正确，请重新输入")
    }
})
// 用户名验证是否合法
var reg2 = /^[0-9a-zA-Z-]{6,16}$/;
$(".uname").blur(function(){
    if(reg2.test($(this).val())){
        $(this).siblings("span").attr("class","success");
        $(this).siblings("span").html("<i class='success_ico'></i>用户名输入正确")
    }else{
        $(this).siblings("span").attr("class","error");
        $(this).siblings("span").html("<i class='error_ico'></i>用户名格式不正确,请重新输入")
    }
})
// 密码验证
var reg3 = /^[0-9a-zA-Z-]{6,16}$/;
$(".password").blur(function(){
    if(reg3.test($(this).val())){
        $(this).siblings("span").attr("class","success");
        $(this).siblings("span").html("<i class='success_ico'></i>格式正确")
    }else{
        $(this).siblings("span").attr("class","error");
        $(this).siblings("span").html("<i class='error_ico'></i>密码格式不正确,请重新输入")
    }
})
// 判断两次密码输入密码是否一致
$(".ppassword").blur(function(){
    if($(this) !== null || $(this) !== ""){
          if($(this).val() === $(".password").val()){
            $(this).siblings("span").attr("class","success");
            $(this).siblings("span").html("<i class='success_ico'></i>输入正确")
          }else{
            $(this).siblings("span").attr("class","error");
            $(this).siblings("span").html("<i class='error_ico'></i>密码不一致,请重新输入")
          }
    }
    else{
        alert("密码不能为空")
    }
})
